var parkingLot1 = []; //停车场1
var parkingLot2 = []; //停车场2
var parkingLotCapacity = 50;//停车场容量

//停车
function park(car) {
    if (isEmpty(car)) {
        return 'error'
    }
    if (parkingLot1.length < parkingLotCapacity) {
        parkingLot1.push(car);
        return 'success';
    }
    if (parkingLot2.length < parkingLotCapacity) {
        parkingLot2.push(car);
        return 'success';
    }
    reportError('停车场已满！');
    return 'error';
}

//取车
function pick(car) {
    //在停车场1中查找车辆
    var pickIndex = parkingLot1.findIndex((value) => value === car);
    if (!isEmpty(pickIndex)) {
        parkingLot1.splice(pickIndex, 1);
        return car;
    }
     //在停车场2中查找车辆
    pickIndex = parkingLot2.findIndex((value) => value === car);
    if (!isEmpty(pickIndex)) {
        parkingLot2.splice(pickIndex, 1);
        return car;
    }
    reportError('车辆不存在！');
    return 'error';
}

//判断传入参数是否为空
function isEmpty(param) {
    return param === undefined || param === null
}

//报错
function reportError(err) {
    alert(err);
}

export default{
    park,
    pick
}